package com.study.test;

import com.study.lock.ZkLock;
import com.study.pojo.Stock;

/**
 * @author dejawu
 * @Title: StcokMain
 * @Description: TODO
 * @date 2020/12/29
 */
public class StockMain {

    private static ZkLock zkLock;

    static {
        zkLock = new ZkLock("127.0.0.1:2181", "stock_zk");
    }

    static class StockThread implements Runnable {

        @Override
        public void run() {
            zkLock.lock();
            boolean b = new Stock().reduceStock();
            zkLock.unlock();
            if (b) {
                System.out.println(Thread.currentThread().getName() + "减少库存成功");
            } else {
                System.out.println(Thread.currentThread().getName() + "减少库存失败");
            }
        }
    }

    public static void main(String[] args) {
        new Thread(new StockThread(), "线程一").start();
        new Thread(new StockThread(), "线程二").start();
    }
}
